package com.cm386.final_project_timezonealert.model;

import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

public class CityService {
	public static List<City> getCitiesByRegion(String region){
		List<City> cities = new ArrayList<City>();
		String[] timezoneIDs = TimeZone.getAvailableIDs();
		for (String timezoneID : timezoneIDs){
			if (timezoneID.startsWith(region)){
				String[] regionCity = timezoneID.split("/");
				if (regionCity.length > 1 && 
					regionCity[0].equalsIgnoreCase(region) &&
					!regionCity[regionCity.length - 1].startsWith("GMT")){
					cities.add(new City(regionCity[regionCity.length - 1], timezoneID, TimeZone.getTimeZone(timezoneID), regionCity[0]));
				}
			}
		}
		return cities;
	}
}
